/**
  \mainpage
  ETFRoot project, Anyang Normal University && IMP-CAS
  \brief analyse the raw data, including data mapping, tracking and PID
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2022-04-27
  \date 2022-04-27 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2022-04-27   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2022 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

void anaL(){
  // VMCWORKDIR: path to ETFAna root directory -> used to indicate path to config files
  setenv("VMCWORKDIR", TString(get_current_dir_name())+"/../ETFAna", true);
  ETFMsg::SetDebug(); // display debug info

  auto source = new ETFPXIOfflineSource("../20220425_1151.dat");
  FairRunOnline *run = new FairRunOnline(source);
  source->AddUnpacker(new ETFPXIUnpacker());
  run->SetSink(new FairRootFileSink(source->ROOTFileName()));
  auto unpackTask = new ETFUserUnpackTask();
  // unpackTask->SetDebug();
  run->AddTask(unpackTask); // add analysis task
  ETFAnaTask *anaTask = new ETFAnaLTask();
  // anaTask->SetDetDebug();
  // anaTask->SetTrackingDebug();
  run->AddTask(anaTask); // add analysis task
  /// analysis level: 0: only mapping; 1: 2D tracking; 2: PID;
  anaTask->SetConfigFolder("LiuApr2022");
  anaTask->SetChIdConfigFile("chIdMap.yaml");
  anaTask->SetDetPosConfigFile("detPos.yaml");
  anaTask->SetDelayConfigFile("delay.yaml");
  anaTask->SetMisConfigFile("mis.yaml"); // miscellaneous parameters
  //////////   set analysis depth   //////////
  anaTask->SetAnaLevel(1); // -1: unpacking; 0: assigning to dets; 1: tracking
  anaTask->SetIs3DTracking(true);
  // anaTask->AddDrawEvent({3484}); // add events to be drawn
  run->Init();

  TStopwatch timer;
  // prepare and read the events
  timer.Start();
  run->Run(0, 1000); // (ev_start, ev_stop): set ev_start<0 to run all the events
  timer.Stop();

  cout << endl << "Real time: " << timer.RealTime() << "s" << endl;
  cout << "CPU time: " << timer.CpuTime() << "s." << endl;
} // end the main function sim
